Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change tool metadata file format to JSON #1553

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

vicroms
Copy link
Member

@vicroms vicroms commented Dec 13, 2024

Continuation of #1490
Related: #1277

This PR contains several changes:

  • Moves vcpkgTools.xml data into a JSON file and removes the XML parsing code.
  • Adds the architecture field to the tool metadata.
  • Removes the requirement of force system binaries on arm64 Linux platforms.

To do:

  • Update Ninja version to one with ARM64 support.
  • Test with full registry build.

@vicroms vicroms force-pushed the tools branch 2 times, most recently from 5fe30dc to 3747fae Compare December 13, 2024 09:46
@vicroms vicroms changed the title [WIP] Add ARM64 Linux tools [WIP] Change tool metadata file format to JSON Dec 13, 2024
@vicroms vicroms changed the title [WIP] Change tool metadata file format to JSON Change tool metadata file format to JSON Dec 16, 2024
Copy link
Member

@BillyONeal BillyONeal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feature!

Comment on lines +1656 to +1660
if (Util::contains(KNOWN_ARCHITECTURES, sv))
{
return sv.to_string();
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (Util::contains(KNOWN_ARCHITECTURES, sv))
{
return sv.to_string();
}
if (to_cpu_architecture(sv).has_value()) { return sv.to_string(); }

?

Alternately, can this just be made to return CPUArchitecture directly instead? This also avoids the need to have a duplicate KNOWN_ARCHITECTURES table.

(If you still want the table to generate the error message, can it at least be combined with the bits powering to_cpu_architecture so that we don't introduce a bug any time any of those are edited? For example:

struct KnownCPUArchitecture {
    StringLiteral name;
    CPUArchitecture architecture;
};

inline constexpr KnownCPUArchitecture KnownArchitectures[] = {
    {"x86", CPUArchitecture::X86},
    {"x64", CPUArchitecture::X64},
    {"amd64", CPUArchitecture::X64},
    {"arm", CPUArchitecture::ARM},
    {"arm64", CPUArchitecture::ARM64},
    {"arm64ec", CPUArchitecture::ARM64EC},
    {"s390x", CPUArchitecture::S390X},
    {"ppc64le", CPUArchitecture::PPC64LE},
    {"riscv32", CPUArchitecture::RISCV32},
    {"riscv64", CPUArchitecture::RISCV64},
    {"loongarch32", CPUArchitecture::LOONGARCH32},
    {"loongarch64", CPUArchitecture::LOONGARCH64},
    {"mips64", CPUArchitecture::MIPS64},
};

)

@@ -358,6 +358,7 @@ namespace vcpkg
args.parser.parse_option(
SwitchBuiltinRegistryVersionsDir, StabilityTag::Experimental, args.builtin_registry_versions_dir);
args.parser.parse_option(SwitchRegistriesCache, StabilityTag::Experimental, args.registries_cache_dir);
args.parser.parse_option(SwitchToolDataFile, StabilityTag::ImplementationDetail, args.tools_data_file);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget docs :)

@@ -1,6 +1,7 @@
#pragma once
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really think this should just be in tools.h given that the things in here are contractual despite trying to claim that it's used for 'test'ing. But that's a preexisting situation so no change requested if you don't want to go there.

REQUIRE(!invalid_arch.has_value());
CHECK("invalid_arch.json: error: $.tools[0].arch (a CPU architecture): Invalid architecture: notanarchitecture. "
"Expected "
"one of: x86,x64,arm,arm64,arm64ec,s390x,ppc64le,riscv32,riscv64,loongarch32,loongarch64,mips64\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"one of: x86,x64,arm,arm64,arm64ec,s390x,ppc64le,riscv32,riscv64,loongarch32,loongarch64,mips64\n"
"one of: x86, x64,arm, arm64, arm64ec, s390x, ppc64le, riscv32, riscv64, loongarch32, loongarch64,mips64\n"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"one of: x86,x64,arm,arm64,arm64ec,s390x,ppc64le,riscv32,riscv64,loongarch32,loongarch64,mips64\n"
"one of: x86, x64, arm, arm64, arm64ec, s390x, ppc64le, riscv32, riscv64, loongarch32, loongarch64, mips64\n"

Comment on lines +82 to +87
if (auto tool_data = maybe_tool_data.get())
{
return *tool_data;
}

return msg::format(msgErrorWhileParsingToolData, msg::path = origin);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (auto tool_data = maybe_tool_data.get())
{
return *tool_data;
}
return msg::format(msgErrorWhileParsingToolData, msg::path = origin);
return maybe_tool_data.value_or_exit(VCPKG_LINE_INFO);

Any errors in parsing should have been reported by Json::Reader, so if we get here vcpkg has a bug and we shouldn't have separate localized messages for bugs.

Comment on lines +68 to +73
auto as_json = Json::parse(contents, origin);
if (!as_json)
{
return as_json.error();
}
auto as_value = std::move(as_json).value(VCPKG_LINE_INFO).value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have error handling like that in Json::parse_object rather than crashing if it can't be interpreted as a value here.

Comment on lines +92 to +99
std::error_code ec;
auto contents = fs.read_contents(path, ec);
if (ec)
{
return format_filesystem_call_error(ec, __func__, {path});
}

return parse_tool_data(contents, path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::error_code ec;
auto contents = fs.read_contents(path, ec);
if (ec)
{
return format_filesystem_call_error(ec, __func__, {path});
}
return parse_tool_data(contents, path);
return fs.try_read_contents(path).then([](FileContents&& fc) -> ExpectedL<std::vector<ToolDataEntry>> {
return parse_tool_data(fc.content, Path{fc.origin});
});

std::string arch_str;
if (r.optional_object_field(obj, "arch", arch_str, Json::ArchitectureDeserializer::instance))
{
auto it = arch_map.find(arch_str);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use to_cpu_architecture instead of a second duplicate table?

Copy link
Contributor

@autoantwort autoantwort left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a json schema for this file?

Comment on lines +61 to +67
"name": "cmake",
"os": "linux",
"version": "3.22.2",
"executable": "cmake-3.22.2-linux-x86_64/bin/cmake",
"url": "https://github.com/Kitware/CMake/releases/download/v3.22.2/cmake-3.22.2-linux-x86_64.tar.gz",
"sha512": "579e08b086f6903ef063697fca1dc2692f68a7341dd35998990b772b4221cdb5b1deecfa73bad9d46817ef09e58882b2adff9d64f959c01002c11448a878746b",
"archive": "cmake-3.22.2linux-x86_64.tar.gz"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this entry has no architecture entry this version would be used on arm64 devices. Maybe the arch field should be mandatory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants